package operations;
import Book.*;

import java.util.Scanner;

//添加书籍
public class AddOperation implements IOperation{
    public void work(BookList booklist){
        System.out.println("添加图书");
        System.out.println("请输入你想添加的书籍的名字");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        System.out.println("请输入你想添加的书籍的作者");
        String author = sc.nextLine();
        System.out.println("请输入你想添加的书籍的价格");
        float price = sc.nextFloat();

        sc.nextLine();//将价格输入后敲得回车读进去，避免下面无法输入类型
        System.out.println("请输入你想添加的书籍的类型");
        String type = sc.nextLine();

        //将书籍放入
        //1.获取到当前可以存放书籍的位置
        int currentSize = booklist.getUsedsize();
        //2。把书放入指定位置
        Book book = new Book(name,author,price,type);
        //3.书的数目加1
        booklist.setBooks(book,currentSize);
        booklist.setUsedsize(currentSize+1);
    }

}
